package book;

import java.util.ArrayList;
import java.util.List;

public class BookList {
    private List<Book> books;

    public BookList() {
        this.books = new ArrayList<>();
        // 添加默认书籍
        this.books.add(new Book("三国演义","罗贯中",10,"小说",false));
        this.books.add(new Book("西游记","吴承恩",20,"小说",false));
        this.books.add(new Book("红楼梦","曹雪芹",18,"小说",false));
    }

    // 接受Book数组的构造方法
    public BookList(Book[] bookArray) {
        this.books = new ArrayList<>();
        if (bookArray != null) {
            for (Book book : bookArray) {
                if (book != null) {
                    this.books.add(book);
                }
            }
        }
    }

    public Book getBook(int i) {
        if (i >= 0 && i < books.size()) {
            return books.get(i);
        }
        return null;
    }

    public void setBook(Book book) {
        if (book != null) {
            this.books.add(book);
        }
    }
    
    public void setBook(int i, Book book) {
        if (i >= 0 && i < books.size() && book != null) {
            this.books.set(i, book);
        }
    }
    
    public List<Book> getBooks() {
        return books;
    }

    public int getUsedsize() {
        return books.size();
    }

    public int getLength() {
        return books.size();
    }
}
